package com.csdj.thread;

import java.util.concurrent.TimeUnit;

public class TicketThread implements Runnable{

    private int ticket=200;
    //抢到的票
    private int buy = 0;
    //退出标记
    private boolean flag = true;
    @Override
    public void run() {
        while(ticket>0){
            sale();
        }

        synchronized (this){
            System.out.println("ss");
        }
    }

    public synchronized void sale(){
        if(ticket <= 0){
            flag = false;
            return;
        }
        buy++;
        ticket--;
        System.out.println(Thread.currentThread().getName()+"抢到了"+buy+"张票，还剩余"+ticket+"张票");
    }
}
